package {
	import as3isolib.display.IsoView;
	import as3isolib.display.primitive.IsoBox;
	import as3isolib.display.primitive.IsoRectangle;
	import as3isolib.display.scene.IsoGrid;
	import as3isolib.display.scene.IsoScene;
	import as3isolib.graphics.SolidColorFill;
	import as3isolib.graphics.Stroke;
	import flash.display.Sprite;
	import flash.events.Event;

	/**
	 */
	public class PrimitiveDemo_final extends Sprite {
		private var _world:IsoView;
		private var _scene:IsoScene;

		public function PrimitiveDemo_final() {
			addEventListener(Event.ADDED_TO_STAGE, init);
		}

		private function init(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);

			//1. buat isoview
			_world = new IsoView();
			_world.setSize(800, 600);

			//2. buat isoscene
			_scene = new IsoScene();

			//3. tambahkan scene ke isoview
			_world.addScene(_scene);

			//4. buat iso objects & tambahkan ke scene
			createBox(_scene, 20, 30, 40, 0x8080C0, 10, 20);
			createBox(_scene, 20, 10, 60, 0x0080FF, 60, 80);
			createBox(_scene, 20, 60, 30, 0x00FF00, 30, 45, 20);
			createRectangle(_scene, 300, 300, 0x8000FF, 0, 0);
			createRectangle(_scene, 10, 300, 0xFF8040, 60, 50, 40);

			//5. render
			//tambahkan isoview ke displaylist
			addChild(_world);
			//render
			_world.render(true);

			////////////////////////////////////////////
			//OPTIONAL : Grid
			///////////////////////////////////////////
			var g:IsoGrid = new IsoGrid();
			g.setGridSize(20, 20);
			g.cellSize = 20;
			g.strokes = [new Stroke(0, 0)];

			var gscene:IsoScene = new IsoScene();
			gscene.addChild(g);

			_world.addSceneAt(gscene, 0);
			_world.render(true);

		}

		private function createRectangle(scene:IsoScene, width:Number, length:Number, color:uint, x:Number, y:Number, z:Number = 0):void {
			var rect:IsoRectangle = new IsoRectangle();
			var fill:SolidColorFill = new SolidColorFill(color, 1);
			rect.fills = [fill];
			rect.setSize(width, length, 0);
			rect.moveTo(x, y, z);

			scene.addChild(rect);

		}

		private function createBox(scene:IsoScene, width:Number, length:Number, height:Number, color:uint, x:Number, y:Number, z:Number = 0):void {
			var box:IsoBox = new IsoBox();
			var fill:SolidColorFill = new SolidColorFill(color, 1);
			box.fills = [fill, fill, fill];
			box.setSize(width, length, height);
			box.moveTo(x, y, z);

			scene.addChild(box);
		}

	}

}